package android.slc.appbase.ui.activity;

import android.os.Bundle;
import android.slc.appbase.ui.activity.base.AppMvvmBaseToolBarActivity;
import android.slc.appbase.vm.AppBaseViewModel;

import androidx.annotation.Nullable;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;

/**
 * @author slc
 * @date 2020-08-25 15:25
 */
public abstract class BaseCommonListShelfActivity<V extends ViewDataBinding, VM extends AppBaseViewModel> extends AppMvvmBaseToolBarActivity<V, VM> {

    /**
     * 获取viewpager
     *
     * @return
     */
    protected abstract ViewPager getViewPager();

    /**
     * 获取滑动的索引
     *
     * @return
     */
    protected abstract MagicIndicator getMagicIndicator();

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState) {
        super.onBindView(savedInstanceState);
        initTable();
        bindTablePager();
        bindPager();
    }

    /**
     * 初始化索引和table
     */
    protected abstract void initTable();

    /**
     * 绑定索引和viewpager
     */
    protected void bindTablePager() {
        ViewPagerHelper.bind(getMagicIndicator(), getViewPager());
    }

    /**
     * 绑定pager
     */
    protected void bindPager() {
        getViewPager().setAdapter(getFragmentPagerAdapter());
    }

    protected abstract FragmentPagerAdapter getFragmentPagerAdapter();
}
